import axios from 'axios';
import getEnv from '@/config/axios.config';

// 创建axios实例
const instance = axios.create({
    baseURL: getEnv,
    timeout: 10000,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
    },
    // 是否自动发送 cookie
    withCredentials: true
});

// request过滤器
instance.interceptors.request.use(
    config => {
        config.headers['authorization'] = `Bearer token`;
        return config;
    },
    err => {
        return Promise.reject(err);
    }
);

// response过滤器
instance.interceptors.response.use(
    response => {
        // 未登录
        if (response.data.status === 401) {
        }
        return response;
    },
    err => {
        return Promise.reject(err);
    }
);

// 返回axios实例
export default instance;
